package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbAddressMapper;
import com.dongdongshop.mapper.TbAreasMapper;
import com.dongdongshop.mapper.TbCitiesMapper;
import com.dongdongshop.mapper.TbProvincesMapper;
import com.dongdongshop.pojo.*;
import com.dongdongshop.service.TbAddressService;
import com.dongdongshop.vo.AddressVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//地址管理
@Service
@DubboService
public class TbAddressServiceimpl implements TbAddressService {


    @Autowired
    TbAddressMapper tm;//地址信息

    @Autowired
    TbAreasMapper tam;//县

    @Autowired
    TbCitiesMapper tcm; //市

    @Autowired
    TbProvincesMapper tpm;//省


    //查询全部
    @Override
    public List<TbAddress> getall() {
        return tm.selectByExample(null);
    }

    //省查询全部
    @Override
    public List<TbProvinces> getsanji() {
        return tpm.selectByExample(null);
    }


    //获取市
    @Override
    public List<TbCities> getcity(String provinceid) {
        TbCitiesExample te=new TbCitiesExample();
        TbCitiesExample.Criteria criteria = te.createCriteria();
        criteria.andProvinceidEqualTo(provinceid);
        return tcm.selectByExample(te);
    }

    //获取县
    @Override
    public List<TbAreas> getarea(String cityid) {
        TbAreasExample ta=new TbAreasExample();
        TbAreasExample.Criteria criteria = ta.createCriteria();
        criteria.andCityidEqualTo(cityid);
        return tam.selectByExample(ta);
    }

    //增加
    @Override
    public int insertadd(TbAddress ta) {
        return tm.insertSelective(ta);
    }


    //回显
    @Override
    public TbAddress upbyid(Long id) {
        return tm.selectByPrimaryKey(id) ;
    }

    //修改
    @Override
    public int updateadd(TbAddress ta) {
        return tm.updateByPrimaryKeySelective(ta);
    }

    //删除
    @Override
    public int deletebyid(Long id) {
        return tm.deleteByPrimaryKey(id);
    }

    //省
    @Override
    public List<TbProvinces> getsheng() {
        return tpm.selectByExample(null);
    }

    //市
    @Override
    public List<TbCities> getshi() {
        return tcm.selectByExample(null);
    }

    //县
    @Override
    public List<TbAreas> getxian() {
        return tam.selectByExample(null);
    }


    //查询全部vo封装所有
    @Override
    public List<AddressVo> getaddVo(String username) {
        return tm.AddgetVo(username);
    }


    //更具用户查询收货地址
    @Override
    public List<TbAddress> getAddress(String username) {
        TbAddressExample te=new TbAddressExample();
        TbAddressExample.Criteria criteria = te.createCriteria();
        criteria.andUserIdEqualTo(username);
        return tm.selectByExample(te);
    }


    //根据用户id查询
    @Override
    public AddressVo getaddVoid(Long userid) {
        return tm.getaddVoid(userid);
    }
}
